package com.xxwy.spring.event;

import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.support.GenericApplicationContext;

/**
 * {@link ApplicationListener} 实例.
 *
 * @author xxwy
 * @date 2021/9/16 0016
 */
public class ApplicationListenerDemo {

    public static void main(String[] args) {
        GenericApplicationContext applicationContext = new GenericApplicationContext();
        applicationContext.addApplicationListener(new ApplicationListener<ApplicationEvent>() {
            @Override
            public void onApplicationEvent(ApplicationEvent event) {
                System.out.println("接受到Spring 事件 : " + event);
            }
        });
        // 启动Spring上下文
        applicationContext.refresh();
        applicationContext.start();

        applicationContext.close();
    }
}
